package com.haocjia.droolsdemo.service.impl;

import com.haocjia.droolsdemo.domain.TestInfo;
import com.haocjia.droolsdemo.repository.TestInfoRepository;
import com.haocjia.droolsdemo.service.ITestInfoService;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class TestInfoService implements ITestInfoService {

    final TestInfoRepository repository;

    public TestInfoService(TestInfoRepository repository) {
        this.repository = repository;
    }

    @Override
    public void add(TestInfo testInfo) {
        repository.save(testInfo);
    }

    @Override
    public TestInfo get(TestInfo testInfo) {
        Example<TestInfo> example = Example.of(testInfo);
        Optional<TestInfo> info = repository.findOne(example);
        if (info.isPresent()){
            return info.get();
        }
        return null;
    }
}
